package com.entrogy.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;



@Configuration
@ConditionalOnProperty(prefix = "swagger",value = {"enable"},havingValue = "true")
@EnableSwagger2
@Profile("dev")
public class SwaggerConfig {

    /*@Autowired
    private Environment env;
    */
    @Bean
    public Docket createRestApi() {


        ParameterBuilder tokenPar = new ParameterBuilder();
        List<Parameter> pars = new ArrayList<Parameter>();
           /* tokenPar.name("tk").defaultValue("C6x eyJhbGciOiJIUzUxMiJ9.eyJ1aWQiOiJcdMOkKsKFwqxcdTAwMDPClcKjw69cbsKtw6NcZsOhTnMiLCJleHAiOjE1MTgxNTY0NjF9.uvE48kR3Aw1oThbbLyu1LMz1eslGlChZyQkV0iUbcm2Fv55wFK1JAOu-GUS_uIhDlQXonGcIgdg0KgGEjGuY5w").description("令牌").modelRef(new ModelRef("string"))
                    .parameterType("header").required(false).build();
            pars.add(tokenPar.build());*/
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.entrogy.controller"))
                .paths(PathSelectors.any())
                .build()
                .globalOperationParameters(pars)
                ;
    }

    private ApiInfo apiInfo() {
        Contact contact=new Contact("作者名",
                " ","email地址");
        return new ApiInfoBuilder()
                .title("Spring Boot中使用Swagger2")
                .description("Hello Swagger2")
                //.contact("作者名")
                .contact(contact)
                .version("1.0")
                .build();
    }


}
